package com.woniu.apidriver.service;

import com.woniu.internalcommon.dto.Car;
import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.remote.ServiceDriverUserClient;
import com.woniu.internalcommon.remote.ServiceMapClient;
import com.woniu.internalcommon.request.ApiDriverPointRequest;
import com.woniu.internalcommon.request.PointRequest;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class PointService {
    @Resource
    private ServiceMapClient serviceMapClient;

    @Resource
    private ServiceDriverUserClient serviceDriverUserClient;

    /**
     * 上传汽车轨迹数据
     * @param apiDriverPointRequest
     * @return
     */
    public ResponseResult upload(ApiDriverPointRequest apiDriverPointRequest){
        // 获取carId
        Long carId = apiDriverPointRequest.getCarId();

        // 通过carId 获取 tid、trid，调用 service-driver-user的接口
        ResponseResult<Car> carById = serviceDriverUserClient.getCarById(carId);
        Car car = carById.getData();
        String tid = car.getTid();
        String trid = car.getTrid();

        // 调用地图去上传
        PointRequest pointRequest = new PointRequest();
        pointRequest.setTid(tid);
        pointRequest.setTrid(trid);
        pointRequest.setPoints(apiDriverPointRequest.getPoints());

        return serviceMapClient.uploadTrack(pointRequest);

    }
}
